home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_client_form.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  18.9 KB  |  799 lines

  1. unit ntc_client_form;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Classes,
  30.     Graphics,
  31.     Controls,
  32.     Forms,
  33.     Dialogs,
  34.     ShellAPI,
  35.     StdCtrls,
  36.     Buttons,
  37.     inifiles,
  38.     ComCtrls,
  39.     Menus,
  40.     ExtCtrls,
  41.     Mask,
  42.     ScktComp,
  43.  
  44.     ntc_client_button;
  45.  
  46. const
  47.     { network }
  48.     socket_number=8383;
  49.     { messages }
  50.     no_response='No response from server';
  51.     lost_connection='lost connection with server';
  52.     stop_error='NTC failed to stop the scope, '+
  53.                          'it could be that there is a error '+
  54.                          'or the network connection has failed';
  55.     { events }
  56.     event_0=0;
  57.     { scope types }
  58.     no_scope=0;
  59.     lx200_type=1;
  60.     autostar_type=2;
  61.     { interface }
  62.     button_width=57;
  63.     max_menu_items=10;
  64.  
  65. type
  66.     p_dimensions_record=^dimensions_record;
  67.     dimensions_record=record
  68.         vdu_index,
  69.         old_vdu_index,
  70.         screen_left,
  71.         screen_top,
  72.         last_screen_height,
  73.         last_screen_width,
  74.         current_height,
  75.         current_width,
  76.         form_top,
  77.         form_left:integer;
  78.     end;
  79.  
  80.     Tscope = class(TForm)
  81.     controller_pages: TPageControl;
  82.  
  83.         { constructors etc }
  84.         procedure formcreate(
  85.             Sender:TObject);
  86.  
  87.         procedure kill(
  88.                     Sender:TObject;
  89.             var CanClose:Boolean);
  90.  
  91.         { configuration backup }
  92.         procedure get_dimensions(
  93.             form:tform;
  94.             dimensions:p_dimensions_record;
  95.             section:string;
  96.             ini_file:tinifile);
  97.  
  98.         procedure write_dimensions(
  99.             dimensions:p_dimensions_record;
  100.             left,
  101.             top:integer;
  102.             section:string;
  103.             ini_file:tinifile);
  104.  
  105.         procedure load_settings;
  106.         procedure save_settings;
  107.  
  108.         { events }
  109.         procedure control_button_click(
  110.             Sender: TObject);
  111.  
  112.         procedure FormShow(
  113.             Sender: TObject);
  114.  
  115.         procedure find_vdu(
  116.             form:tform;
  117.             dimensions:p_dimensions_record);
  118.  
  119.         procedure form_activate(
  120.             form:tform;
  121.             dimensions:p_dimensions_record);
  122.  
  123.         procedure check_activate(
  124.             Sender: TObject);
  125.  
  126.         procedure change_page;
  127.  
  128.         procedure page_change(
  129.             Sender: TObject);
  130.  
  131.         { menu item event handlers }
  132.         procedure sticky_handler(
  133.             sender:tobject);
  134.  
  135.         procedure buttonContextPopup(
  136.                     Sender: TObject;
  137.                     MousePos: TPoint;
  138.             var Handled: Boolean);
  139.  
  140.     private
  141.         { Private declarations }
  142.         previous_page,
  143.         current_page:ttabsheet;
  144.         active_page:integer;
  145.         { menu handling }
  146.         menu_items:array[1..max_menu_items] of TMenuItem;
  147.         context_menu:tpopupmenu;
  148.         im:integer;
  149.         { menu handler parameters }
  150.         button:tscope_button;
  151.  
  152.     public
  153.         { Public declarations }
  154.         { configuration }
  155.         dimensions:dimensions_record;
  156.  
  157.         { events }
  158.         procedure show_hide(
  159.             sender:tobject;
  160.             v:boolean);
  161.  
  162.     end;
  163.  
  164. { global variables }
  165. var
  166.     scope:tscope;
  167.     application_path:string;
  168.     scope_type:word;
  169.     { configuration }
  170.     ini_file:tinifile;
  171.  
  172. implementation
  173.  
  174. uses
  175.     ntc_client_network,
  176.     ntc_client_control,
  177.     ntc_client_info,
  178.     ntc_client_focus,
  179.     ntc_client_tracking,
  180.     ntc_client_about,
  181.     ntc_client_search,
  182.     ntc_client_sun,
  183.     ntc_client_moon,
  184.     ntc_client_planets,
  185.     ntc_client_catalogs;
  186.  
  187. {$R *.DFM}
  188.  
  189.     { ------------
  190.         constructors
  191.         ------------ }
  192.  
  193. procedure tscope.formcreate(
  194.     Sender:TObject);
  195. begin
  196.     application_path:=extractfilepath(paramstr(0));
  197.     scope_type:=autostar_type;
  198.     previous_page:=nil;
  199.     load_settings;
  200.     controller_pages.activepage:=current_page;
  201. end;
  202.  
  203. procedure tscope.kill(
  204.             Sender:TObject;
  205.     var CanClose:Boolean);
  206. begin
  207.     save_settings;
  208.     scope_network.kill;
  209.     scope_control.free;
  210.     scope_search.free;
  211.     scope_network.free;
  212.     scope_focus.free;
  213.     scope_info.free;
  214.     scope_tracking.free;
  215.     scope_sun.free;
  216.     scope_moon.free;
  217.     scope_planets.free;
  218.     scope_catalogs.free;
  219.     scope_about.free;
  220.     canclose:=true;
  221. end;
  222.  
  223.     { --------------------
  224.         configuration backup
  225.         -------------------- }
  226.  
  227. procedure Tscope.find_vdu(
  228.     form:tform;
  229.     dimensions:p_dimensions_record);
  230. var
  231.     i,lw,lh:integer;
  232.     done,vdu_changed:boolean;
  233.  
  234.     procedure switch_monitor;
  235.     begin
  236.         with dimensions^,screen.monitors[vdu_index] do
  237.             begin
  238.                 if screen_left<0 then
  239.                     begin
  240.                         if form_left>=0 then
  241.                             form_left:=form_left+screen_left+left
  242.                         else
  243.                             form_left:=abs(form_left-screen_left)+left;
  244.                     end
  245.                 else
  246.                     form_left:=form_left-screen_left+left;
  247.                 if screen_top<0 then
  248.                     begin
  249.                         if form_top>=0 then
  250.                             form_top:=form_top+screen_top+top
  251.                         else
  252.                             form_top:=abs(form_top-screen_top)+top;
  253.                     end
  254.                 else
  255.                     form_top:=form_top-screen_top+top;
  256.                 screen_left:=left;
  257.                 screen_top:=top;
  258.             end;
  259.     end;
  260.  
  261. begin
  262.     with screen,dimensions^ do
  263.         begin
  264.             vdu_changed:=false;
  265.             if vdu_index>=0 then
  266.                 begin
  267.                     i:=0;
  268.                     if (old_vdu_index>=0) and (old_vdu_index<monitorcount) then
  269.                         begin
  270.                             if old_vdu_index<>vdu_index then
  271.                                 begin
  272.                                     vdu_index:=old_vdu_index;
  273.                                     switch_monitor;
  274.                                 end;
  275.                             old_vdu_index:=-1;
  276.                         end;
  277.                     done:=false;
  278.                     while not done do
  279.                          if i<monitorcount then
  280.                          with monitors[i] do
  281.                         begin
  282.                             if (form_left<left) or
  283.                                  (form_left>left+width) or
  284.                                  (form_top<top) or
  285.                                  (form_top>top+height) then
  286.                                 inc(i)
  287.                             else
  288.                                 begin
  289.                                     if i<>vdu_index then
  290.                                         vdu_index:=i;
  291.                                     done:=true;
  292.                                 end;
  293.                         end
  294.                     else
  295.                         begin
  296.                             done:=true;
  297.                             vdu_changed:=true;
  298.                             vdu_index:=-1;
  299.                         end;
  300.                 end;
  301.             if vdu_index<0 then
  302.                 begin
  303.                     i:=0;
  304.                     while (i<monitorcount) and not monitors[i].Primary do
  305.                         inc(i);
  306.                     if i<monitorcount then
  307.                         vdu_index:=i
  308.                     else
  309.                         vdu_index:=0;
  310.                     vdu_changed:=true;
  311.                 end;
  312.             with monitors[vdu_index] do
  313.                 begin
  314.                     if vdu_changed then
  315.                         switch_monitor;
  316.                     lw:=current_width;
  317.                     lh:=current_height;
  318.                     if (lw<>width) or (lh<>height) then
  319.                         begin
  320.                             current_width:=width;
  321.                             current_height:=height;
  322.                             form_left:=trunc(form_left/last_screen_width*current_width);
  323.                             if form_left+form.width>left+current_width then
  324.                                 form_left:=left+current_width-form.Width;
  325.                             if form_left<left then
  326.                                 form_left:=left;
  327.                             form_top:=trunc(form_top/last_screen_height*current_height);
  328.                             if form_top+form.height>top+current_height then
  329.                                 form_top:=top+current_height-form.height;
  330.                             if form_top<top then
  331.                                 form_top:=top;
  332.                             last_screen_width:=current_width;
  333.                             last_screen_height:=current_height;
  334.                         end
  335.                     else
  336.                         begin
  337.                             current_width:=width;
  338.                             current_height:=height;
  339.                         end;
  340.                 end;
  341.         end;
  342. end;
  343.  
  344. procedure tscope.get_dimensions(
  345.     form:tform;
  346.     dimensions:p_dimensions_record;
  347.     section:string;
  348.     ini_file:tinifile);
  349. begin
  350.     with ini_file,dimensions^ do
  351.         begin
  352.             vdu_index:=readinteger(section,'monitor',-1);
  353.             old_vdu_index:=readinteger(section,'another_monitor',-1);
  354.             form_top:=readinteger(section,'top',form_top);
  355.             form_left:=readinteger(section,'left',form_left);
  356.             screen_left:=readinteger(section,'screen_left',0);
  357.             screen_top:=readinteger(section,'screen_top',0);
  358.             last_screen_width:=readinteger(section,'screen_width',-1);
  359.             current_width:=last_screen_width;
  360.             last_screen_height:=readinteger(section,'screen_height',-1);
  361.             current_height:=last_screen_height;
  362.             find_vdu(form,dimensions);
  363.         end;
  364. end;
  365.  
  366. procedure tscope.write_dimensions(
  367.     dimensions:p_dimensions_record;
  368.     left,
  369.     top:integer;
  370.     section:string;
  371.     ini_file:tinifile);
  372. var
  373.     i:integer;
  374. begin
  375.     with ini_file,screen,dimensions^ do
  376.         begin
  377.             for i:=0 to monitorcount-1 do
  378.                  if monitors[i].primary and (vdu_index<>i) then
  379.                 old_vdu_index:=vdu_index;
  380.             writeinteger(section,'another_monitor',old_vdu_index);
  381.             writeinteger(section,'monitor',vdu_index);
  382.             writeinteger(section,'left',left);
  383.             writeinteger(section,'top',top);
  384.             writeinteger(section,'screen_width',current_width);
  385.             writeinteger(section,'screen_height',current_height);
  386.             writeinteger(section,'screen_left',monitors[vdu_index].left);
  387.             writeinteger(section,'screen_top',monitors[vdu_index].top);
  388.         end;
  389. end;
  390.  
  391. procedure tscope.load_settings;
  392. var
  393.     l,m,ip,ib,t:integer;
  394.     p,b,bn:string;
  395.     pd,bd,h,s:boolean;
  396.     ts:ttabsheet;
  397.  
  398.     procedure add_control_page(
  399.         page_name:string);
  400.     begin
  401.         with controller_pages do
  402.             begin
  403.                 ts:=ttabsheet.create(self);
  404.                 with ts do
  405.                     begin
  406.                         pagecontrol:=controller_pages;
  407.                         caption:=page_name;
  408.                         l:=0;
  409.                     end;
  410.             end;
  411.     end;
  412.  
  413.     procedure add_button(
  414.         scope_control_object:scope_button_type;
  415.         button_name:string;
  416.         hidden,
  417.         stuck:boolean);
  418.     begin
  419.         with ts,tscope_button.create(ts) do
  420.             begin
  421.                 visible:=false;
  422.                 caption:=button_name;
  423.                 left:=l;
  424.                 width:=button_width;
  425.                 inc(l,button_width);
  426.                 if l>m then
  427.                     m:=l;
  428.                 top:=0;
  429.                 height:=25;
  430.                 parent:=ts;
  431.                 button_hidden:=hidden;
  432.                 if button_hidden then
  433.                     button_stuck:=false
  434.                 else
  435.                     begin
  436.                         button_stuck:=stuck;
  437.                         if stuck then
  438.                             font.style:=[fsbold]
  439.                         else
  440.                             font.style:=[];
  441.                     end;
  442.                 control_type:=scope_control_object;
  443.                 onclick:=control_button_click;
  444.                 oncontextpopup:=buttonContextPopup;
  445.                 visible:=true;
  446.             end;
  447.     end;
  448.  
  449.     procedure add_menu(
  450.         i:integer;
  451.         s:string;
  452.         h:tnotifyevent);
  453.     begin
  454.         if im>max_menu_items then
  455.             scope_network.write_status_log_check('too many menus : '+inttostr(im))
  456.         else
  457.             begin
  458.                 menu_items[im]:=nil;
  459.                 menu_items[im]:=tmenuitem.create(self);
  460.                 with menu_items[im] do
  461.                     begin
  462.                         caption:=s;
  463.                         checked:=false;
  464.                         onclick:=h;
  465.                     end;
  466.                 context_menu.items.add(menu_items[im]);
  467.             end;
  468.         inc(im);
  469.     end;
  470.  
  471. begin
  472.     ini_file:=tinifile.create(application_path+'client.ini');
  473.     scope_type:=ini_file.ReadInteger('main','scope_type',autostar_type);
  474.     { menus }
  475.     context_menu:=tpopupmenu.create(self);
  476.     im:=1;
  477.     add_menu(im,'Sticky Control',sticky_handler);
  478.     { control panel }
  479.     m:=0;
  480.     current_page:=nil;
  481.     with controller_pages,ini_file do
  482.          if readinteger('main','num_control_panels',0)>0 then
  483.         begin
  484.             active_page:=readinteger('main','active_page',0);
  485.             ip:=1;
  486.             pd:=false;
  487.             while not pd do
  488.                 begin
  489.                     p:=readstring('main','panel_'+inttostr(ip),'');
  490.                     if p<>'' then
  491.                         begin
  492.                             add_control_page(p);
  493.                             if active_page=ip then
  494.                                 current_page:=ts;
  495.                             p:='panel_'+inttostr(ip);
  496.                             ib:=1;
  497.                             bd:=false;
  498.                             while not bd do
  499.                                 begin
  500.                                     b:='button_'+inttostr(ib)+'_';
  501.                                     bn:=readstring(p,b+'name','');
  502.                                     if bn<>'' then
  503.                                         begin
  504.                                             t:=readinteger(p,b+'module',0);
  505.                                             h:=readbool(p,b+'hidden',true);
  506.                                             s:=readbool(p,b+'stuck',false);
  507.                                             if t>0 then
  508.                                                 begin
  509.                                                     case t of
  510.                                                         s_info:add_button(s_info,bn,h,s);
  511.                                                         s_focus:add_button(s_focus,bn,h,s);
  512.                                                         s_about:add_button(s_about,bn,h,s);
  513.                                                         s_object:add_button(s_object,bn,h,s);
  514.                                                         s_search:add_button(s_search,bn,h,s);
  515.                                                         s_control:add_button(s_control,bn,h,s);
  516.                                                         s_network:add_button(s_network,bn,h,s);
  517.                                                         s_tracking:add_button(s_tracking,bn,h,s);
  518.                                                         s_sun:add_button(s_sun,bn,h,s);
  519.                                                         s_moon:add_button(s_moon,bn,h,s);
  520.                                                         s_planets:add_button(s_planets,bn,h,s);
  521.                                                         s_catalogs:add_button(s_catalogs,bn,h,s);
  522.                                                     end;
  523.                                                 end;
  524.                                         end
  525.                                     else
  526.                                         bd:=true;
  527.                                     inc(ib);
  528.                                 end;
  529.                         end
  530.                     else
  531.                         pd:=true;
  532.                     inc(ip);
  533.                 end;
  534.             if current_page=nil then
  535.                 begin
  536.                     current_page:=controller_pages.activepage;
  537.                     active_page:=controller_pages.ActivePageIndex+1;
  538.                 end
  539.             else
  540.                 controller_pages.activepage:=current_page;
  541.         end
  542.     else
  543.         begin
  544.             add_control_page('Setup');
  545.             add_button(s_about,'About',true,false);
  546.             add_button(s_network,'Network',true,false);
  547.             add_control_page('Control');
  548.             add_button(s_info,'Info',true,false);
  549.             add_button(s_focus,'Focus',true,false);
  550.             add_button(s_search,'Search',true,false);
  551.             add_button(s_control,'Control',true,false);
  552.             add_button(s_tracking,'Track',true,false);
  553.             current_page:=controller_pages.ActivePage;
  554.             active_page:=controller_pages.ActivePageIndex+1;
  555.             add_control_page('Objects');
  556.             add_button(s_sun,'Sun',true,false);
  557.             add_button(s_moon,'Moon',true,false);
  558.             add_button(s_planets,'Planets',true,false);
  559.             add_button(s_catalogs,'Catalogs',true,false);
  560.         end;
  561.     scope.clientwidth:=m;
  562.     { form }
  563.     get_dimensions(scope,@dimensions,'main',ini_file);
  564.     ini_file.Free;
  565. end;
  566.  
  567. procedure tscope.save_settings;
  568. var
  569.     i,j:integer;
  570.     ps,bs:string;
  571. begin
  572.     ini_file:=tinifile.create(application_path+'client.ini');
  573.     scope_network.save_settings;
  574.     scope_control.save_settings;
  575.     scope_focus.save_settings;
  576.     scope_info.save_settings;
  577.     scope_tracking.save_settings;
  578.     scope_search.save_settings;
  579.     scope_sun.save_settings;
  580.     scope_moon.save_settings;
  581.     scope_planets.save_settings;
  582.     scope_catalogs.save_settings;
  583.     scope_about.save_settings;
  584.     with ini_file do
  585.         begin
  586.             { control panel }
  587.             with controller_pages do
  588.                 begin
  589.                     for i:=0 to pagecount-1 do
  590.                         begin
  591.                             ps:='panel_'+inttostr(i+1);
  592.                             writestring('main',ps,pages[i].caption);
  593.                             for j:=0 to pages[i].ControlCount-1 do
  594.                                  with pages[i],tscope_button(Controls[j]) do
  595.                                 begin
  596.                                     bs:='button_'+inttostr(j+1)+'_';
  597.                                     WriteString(ps,bs+'name',caption);
  598.                                     writestring(ps,bs+'module',inttostr(control_type));
  599.                                     writebool(ps,bs+'hidden',button_hidden);
  600.                                     writebool(ps,bs+'stuck',button_stuck);
  601.                                 end;
  602.                         end;
  603.                     writestring('main','num_control_panels',inttostr(pagecount));
  604.                 end;
  605.             writeinteger('main','active_page',active_page);
  606.             { form }
  607.             find_vdu(scope,@dimensions);
  608.             write_dimensions(@dimensions,left,top,'main',ini_file);
  609.         end;
  610.     ini_file.free;
  611. end;
  612.  
  613.     { ------
  614.         events
  615.         ------ }
  616.  
  617. procedure Tscope.FormShow(
  618.     Sender: TObject);
  619. begin
  620.     with dimensions do
  621.         begin
  622.             top:=form_top;
  623.             left:=form_left;
  624.         end;
  625.     change_page;
  626. end;
  627.  
  628. procedure Tscope.form_activate(
  629.     form:tform;
  630.     dimensions:p_dimensions_record);
  631. var
  632.     w,h:integer;
  633. begin
  634.     with form,dimensions^ do
  635.         begin
  636.             find_vdu(form,dimensions);
  637.             w:=screen.monitors[vdu_index].width;
  638.             h:=screen.monitors[vdu_index].Height;
  639.             if (w<>current_width) or
  640.                  (h<>current_height) then
  641.                 begin
  642.                     last_screen_width:=current_width;
  643.                     last_screen_height:=current_height;
  644.                     current_width:=w;
  645.                     current_height:=h;
  646.                     scope_network.adjust;
  647.                     scope_control.adjust;
  648.                     scope_about.adjust;
  649.                     scope_focus.adjust;
  650.                     scope_info.adjust;
  651.                     scope_sun.adjust;
  652.                     scope_moon.adjust;
  653.                     scope_planets.adjust;
  654.                     scope_catalogs.adjust;
  655.                     form_top:=trunc(form_top/last_screen_height*current_height);
  656.                     form_left:=trunc(form_left/last_screen_width*current_width);
  657.                     top:=form_top;
  658.                     left:=form_left;
  659.                     scope.show;
  660.                 end;
  661.         end;
  662. end;
  663.  
  664. procedure Tscope.check_activate(
  665.     Sender: TObject);
  666. begin
  667.     form_activate(scope,@dimensions);
  668. end;
  669.  
  670. procedure Tscope.show_hide(
  671.     sender:tobject;
  672.     v:boolean);
  673. begin
  674.     with tscope_button(sender) do
  675.          if not v then
  676.         begin
  677.             if button_stuck then
  678.                 font.style:=[];
  679.             button_stuck:=false;
  680.             button_hidden:=true;
  681.         end
  682.     else
  683.         button_hidden:=false;
  684. end;
  685.  
  686. procedure Tscope.control_button_click(
  687.     Sender: TObject);
  688. begin
  689.     with tscope_button(sender) do
  690.         begin
  691.             case control_type of
  692.                 s_info:scope_info.check_visible_and_show_hide(sender);
  693.                 s_focus:scope_focus.check_visible_and_show_hide(sender);
  694.                 s_about:scope_about.check_visible_and_show_hide(sender);
  695.                 s_network:scope_network.check_visible_and_show_hide(sender);
  696.                 s_search:scope_search.check_visible_and_show_hide(sender);
  697.                 s_control:scope_control.check_visible_and_show_hide(sender);
  698.                 s_tracking:scope_tracking.check_visible_and_show_hide(sender);
  699.                 s_sun:scope_sun.check_visible_and_show_hide(sender);
  700.                 s_moon:scope_moon.check_visible_and_show_hide(sender);
  701.                 s_planets:scope_planets.check_visible_and_show_hide(sender);
  702.                 s_catalogs:scope_catalogs.check_visible_and_show_hide(sender);
  703.             end;
  704.         end;
  705. end;
  706.  
  707. procedure tscope.change_page;
  708. var
  709.     i:integer;
  710. begin
  711.     previous_page:=current_page;
  712.     if previous_page<>nil then
  713.          with previous_page do
  714.          for i:=0 to controlcount-1 do
  715.          with tscope_button(controls[i]) do
  716.         begin
  717.             if not button_stuck then
  718.                  case control_type of
  719.                 s_info:scope_info.hide_form;
  720.                 s_about:scope_about.hide_form;
  721.                 s_focus:scope_focus.hide_form;
  722.                 s_network:scope_network.hide_form;
  723.                 s_search:scope_search.hide_form;
  724.                 s_control:scope_control.hide_form;
  725.                 s_tracking:scope_tracking.hide_form;
  726.                 s_sun:scope_sun.hide_form;
  727.                 s_moon:scope_moon.hide_form;
  728.                 s_planets:scope_planets.hide_form;
  729.                 s_catalogs:scope_catalogs.hide_form;
  730.             end;
  731.         end;
  732.     current_page:=controller_pages.ActivePage;
  733.     with current_page do
  734.          for i:=0 to controlcount-1 do
  735.          with tscope_button(controls[i]) do
  736.         begin
  737.             if not button_hidden then
  738.                  case control_type of
  739.                 s_info:scope_info.show_form;
  740.                 s_about:scope_about.show_form;
  741.                 s_focus:scope_focus.show_form;
  742.                 s_network:scope_network.show_form;
  743.                 s_search:scope_search.show_form;
  744.                 s_control:scope_control.show_form;
  745.                 s_tracking:scope_tracking.show_form;
  746.                 s_sun:scope_sun.show_form;
  747.                 s_moon:scope_moon.show_form;
  748.                 s_planets:scope_planets.show_form;
  749.                 s_catalogs:scope_catalogs.show_form;
  750.             end;
  751.         end;
  752.     active_page:=controller_pages.ActivePageIndex+1;
  753. end;
  754.  
  755. procedure Tscope.page_change(
  756.     Sender: TObject);
  757. begin
  758.     change_page;
  759. end;
  760.  
  761.     { -------------------
  762.         menu event handlers
  763.         ------------------- }
  764.  
  765. { menu handlers }
  766. procedure tscope.sticky_handler(
  767.     sender:tobject);
  768. begin
  769.     with tmenuitem(sender) do
  770.         begin
  771.             with button do
  772.                 begin
  773.                     button_stuck:=not button_stuck;
  774.                     if button_stuck then
  775.                         font.Style:=[fsbold]
  776.                     else
  777.                         font.style:=[];
  778.                 end;
  779.         end;
  780. end;
  781.  
  782. procedure tscope.buttonContextPopup(
  783.             Sender: TObject;
  784.             MousePos: TPoint;
  785.     var Handled: Boolean);
  786. begin
  787.     { setup up parameters }
  788.     button:=sender as tscope_button;
  789.     { call popup menu }
  790.     handled:=true;
  791.     with button do
  792.          context_menu.popup(
  793.         scope.left+current_page.left+parent.left+left+mousepos.x,
  794.         scope.top+current_page.top+parent.top+top+mousepos.y);
  795. end;
  796.  
  797. end.
  798.  
  799.